package com.kirayous.gulimall.authserver.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author KiraYous
 * @version V1.0
 * @Package com.kirayous.gulimall.authserver.config
 * @date 2022/4/4 20:43
 */
@Configuration
public class MySessionConfig {


    @Value("${my.domin}")
    String domin;
    @Value("${my.cookieName}")
    String cookieName;
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

        cookieSerializer.setDomainName(domin);
        cookieSerializer.setCookieName(cookieName);

        return cookieSerializer;
    }

    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        //换成jason格式存储到redis中
        return new GenericJackson2JsonRedisSerializer();
    }
}
